//打印模板
function BasicPrintTemplate_main() {
    return {
        dClick: function (cmp, r) {
            BasicPrintTemplate_form().view({
                entityId: r.get('id')
            });
        },
        id: 'BasicPrintTemplate_main',
        xtype: 'jgrid',
        clazz: BasicPrintTemplate,
        order: [],
        where: [],
        top: [{
            text: '模板key',
            name: 'templateKey',
            xtype: 'textfield',
            op: "like"
        }, {
            text: '模板名称',
            name: 'templateName',
            xtype: 'textfield',
            op: "like"
        }, $.search, '->', {
            key: 'A',
            iconCls: ion.add,
            text: '添加打印模板',
            handler: function () {
                BasicPrintTemplate_form().save({
                    grid: ['BasicPrintTemplate_main']
                });
            }
        }, {
            key: 'E',
            iconCls: ion.edit,
            text: '修改打印模板',
            handler: function () {
                BasicPrintTemplate_form().edit({
                    grid: ['BasicPrintTemplate_main']
                });
            }
        }, {
            key: 'D',
            iconCls: ion.del,
            text: '删除模板',
            handler: function () {
                $('BasicPrintTemplate_main').deletes({
                    validate: []
                });
            }
        }],
        columns: [
            {
                width: 140,
                "name": "templateKey"
            },
            {
                width: 200,
                "name": "templateName",
                renderer: function (value, data, record) {
                    return Ext.String.format("<a href='javascript:void(9)' onclick='showPrintTemplate(\"{0}\",\"{1}\")' style='color: #f00;font-weight: bold'>{0}</a>", value, record.get("templateUrl"));
                }
            },
            {
                width: 300,
                "name": "templateUrl"
            }, {
                flex: 1,
                "name": "templateMemo"
            }
        ]
    }
}

function BasicPrintTemplate_form() {
    return $({
        xtype: 'jform',
        clazz: BasicPrintTemplate,
        fieldsSize: 1,
        hides: [],
        width: 400,
        defaults: {
            lw: 100
        },
        validate: [["templateKey = ?", "templateKey", '打印模板key已存在']],
        fields: [
            {
                req: true,
                "name": "templateKey"

            }, {
                req: true,
                "name": "templateName"
            },
            {
                req: true,
                "name": "templateUrl"
            },
            {
                xtype: 'textarea',
                "name": "templateMemo"
            }
        ]
    })
}

function showPrintTemplate(title, url) {
    $({
        src: url,
        xtype: 'iframe'
    }).win({
        maximized: true,
        title: title
    });

}